package com.db.client.data;

import com.db.data.Order;
import com.db.data.Price;
import com.db.protocol.tags.OrderSide;
import com.db.protocol.tags.OrderStatus;
import com.db.protocol.tags.OrderType;

public class ClientOrder implements Order {
	
	private String orderID;

	@Override
	public String getOrderID() {
		return orderID;
	}
	
	private String ticketSymbol;

	@Override
	public String getTicketSymbol() {
		return ticketSymbol;
	}
	
	private int quantity;
	
	@Override
	public int getQuantity() {
		return quantity;
	}
	
	private Price price;

	@Override
	public Price getPrice() {
		return price;
	}

	private OrderSide side;
	
	@Override
	public OrderSide getSide() {
		return side;
	}
	
	private OrderType type;

	@Override
	public OrderType getType() {
		return type;
	}
	
	private OrderStatus status;
	
	public OrderStatus getStatus() {
		return status;
	}
	
	public void setStatus(OrderStatus status, String text) {
		this.status = status;
		this.text = text;
	}
	
	public void setStatus(OrderStatus status) {
		this.status = status;
		this.text = null;
	}

	private String text;
	
	public String getText() {
		return text;
	}

	private static int countOrders = 0;

	private static final String delimiterID = ":";
	
	public ClientOrder(String clientID, String ticketSymbol, OrderSide side, float price, int quantity) {
		countOrders++;
		this.orderID = clientID + delimiterID + String.valueOf(countOrders);
		this.ticketSymbol = ticketSymbol;
		this.quantity = quantity;
		this.price = new Price(price);
		this.type = OrderType.LIMIT;
		this.side = side;
		this.status = null;
	}

	public ClientOrder(String clientID, String ticketSymbol, OrderSide side, int quantity) {
		countOrders++;
		this.orderID = clientID + delimiterID +String.valueOf(countOrders);
		this.ticketSymbol = ticketSymbol;
		this.quantity = quantity;
		this.price = new Price();
		this.type = OrderType.MARKET;
		this.side = side;
		this.status = null;
	}
	
}
